/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.futco.sysconthos.Modelo.Procesos.Daos;

import org.futco.sysconthos.Modelo.Admisiones.Daos.IDAO;
import org.futco.sysconthos.Modelo.Admisiones.Daos.Model;
import org.futco.sysconthos.Modelo.Proceso.MedicoHorario;
import com.mysql.jdbc.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Server
 */
public class MedicoHorarioDAO implements IDAO <MedicoHorario> {
 private Model model;
 private PreparedStatement psInsert;

  public MedicoHorarioDAO() throws SQLException {
        model = Model.getInstance();
    }
    public void insert(MedicoHorario t) throws SQLException {
       if (psInsert == null) {
            String sqlInsert = "INSERT INTO medicohorario (codHorario, codMedico, fecha) VALUES (?,?,?)";
            psInsert = (PreparedStatement) model.getCon().prepareStatement(sqlInsert);

        psInsert.setString(1, t.getCodHorario());
        psInsert.setString(2, t.getCodMedico());
        //java.sql.Date fecha = new java.sql.Date(t.getFecha().getTime());
        psInsert.setString(3,t.getFecha());
         
        psInsert.executeUpdate();
        }
    }

    public void delete(MedicoHorario t) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<MedicoHorario> getAll() throws SQLException {
      MedicoHorario pro=null;
      PreparedStatement ps=null;
      ResultSet rs=null;
      List lista= new LinkedList();

      try{
          String sqlInsert = "Select * from medicohorario";
          ps=(PreparedStatement) model.getCon().prepareStatement(sqlInsert);
          rs=ps.executeQuery();
          while(rs.next()){
              pro=this.loadMedicoHorario(rs);
              lista.add(pro);
          }

      }finally{
          if(rs!=null){
              rs.close();
          }
          if(ps!=null){
              ps.close();
          }
      }
      return lista;
    }

    public List<MedicoHorario> getAllBy(String t, String n) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public MedicoHorario find(Integer id) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void update(String codigo, MedicoHorario t) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    private MedicoHorario loadMedicoHorario(ResultSet rs) throws SQLException {
       MedicoHorario mh=new MedicoHorario();

       mh.setCodHorario(rs.getString("codHorario"));
       mh.setCodMedico(rs.getString("codMedico"));
      // mh.setFecha(rs.getString("nombre"));
     

      return mh;
    }
}
